package org.evej.apiparser.parser.handler.account;

import org.evej.apiparser.model.account.ApiCharacter;
import org.evej.apiparser.model.account.ApiCharacters;
import org.evej.apiparser.parser.handler.ApiDocumentHandler;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

public class CharactersHandler extends ApiDocumentHandler<ApiCharacters> {

    private ApiCharacters.Builder charactersBuilder = new ApiCharacters.Builder();

    @Override
    public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
        if ("row".equals(qName)) {
            ApiCharacter character = new ApiCharacter(attributeToString(attrs, "name"), attributeToLong(attrs, "characterID"),
                    attributeToString(attrs, "corporationName"), attributeToLong(attrs, "corporationID"));
            charactersBuilder.addCharacter(character);

        }
        super.startElement(uri, localName, qName, attrs);
    }

    @Override
    public void endDocument() throws SAXException {
        super.documentModel = charactersBuilder.build();
        super.endDocument();
    }

}
